package com.example.baseapp.activity

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.baseapp.R
import com.example.baseapp.adpter.TestAdapter
import com.example.baseapp.constants.KeyWords
import com.example.baseapp.entry.TestBean
import com.example.baseapp.topmethod.openActivity
import com.example.baseapp.topmethod.skipActivity
import kotlinx.android.synthetic.main.activity_main.*

/**
 * @作者：HuaCon
 *
 * @类描述：页面入口
 *
 */
class MainActivity : AppCompatActivity() {
    private lateinit var testAdapter: TestAdapter
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        initialDates()
    }

    private fun initialDates() {
        rv_recycleView.layoutManager = LinearLayoutManager(this)
        val data = mutableListOf<TestBean>()

        addItem(data)

        if (!::testAdapter.isInitialized) {
            testAdapter = TestAdapter(data = data)
        }

        testAdapter.apply {
            bindToRecyclerView(rv_recycleView)
        }.apply {
            setOnItemClickListener { _, _, position ->
                when (data[position].keyWordsEnum) {
                    KeyWords.OPERATOR -> skipActivity(OperatorActivity::class.java)
                    KeyWords.HIGHER_ORDER_FUNCTION -> skipActivity(HigherOrderFunctionActivity::class.java)
                    KeyWords.FILE_SAVE -> skipActivity(FileSaveActivity::class.java)
                    KeyWords.DATABASE_TRANSACTION -> skipActivity(DatabaseTransactionActivity::class.java)
                    KeyWords.DELEGATE->skipActivity(DelegateActivity::class.java)
                    KeyWords.COROUTINES->openActivity<CoroutinesActivity>(this@MainActivity)
                    KeyWords.MATERIAL_DESIGN->openActivity<MaterialDesignActivity>(this@MainActivity)
                }
            }
        }
    }

    private fun addItem(dates: MutableList<TestBean>) {
        dates.add(TestBean(KeyWords.OPERATOR))
        dates.add(TestBean(KeyWords.HIGHER_ORDER_FUNCTION))
        dates.add(TestBean(KeyWords.FILE_SAVE))
        dates.add(TestBean(KeyWords.DATABASE_TRANSACTION))
        dates.add(TestBean(KeyWords.DELEGATE))
        dates.add(TestBean(KeyWords.COROUTINES))
        dates.add(TestBean(KeyWords.MATERIAL_DESIGN))
    }
}


